<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Company extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('company', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '公司表']);
        $table->addColumn('group_id', 'integer', ['comment' => '集团id', 'default' => 0])
              ->addColumn('name', 'string', ['limit' => 255, 'default' => '', 'comment' => '公司名称', 'after' => 'group_id'])
              ->addColumn('short_name', 'string', ['limit' => 255, 'default' => '', 'comment' => '公司简称', 'after' => 'name'])
              ->addColumn('license_no', 'string', ['limit' => 100, 'default' => '', 'comment' => '营业执照编号', 'after' => 'short_name'])
              ->addColumn('province_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '省份ID', 'after' => 'short_name'])
              ->addColumn('city_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '城市ID', 'after' => 'province_id'])
              ->addColumn('area_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '区域ID', 'after' => 'city_id'])
              ->addColumn('address', 'string', ['limit' => 255, 'default' => '', 'comment' => '公司地址', 'after' => 'name'])
              ->addColumn('lng', 'string', ['limit' => 255, 'default' => '', 'comment' => '经度', 'after' => 'address'])
              ->addColumn('lat', 'string', ['limit' => 255, 'default' => '', 'comment' => '纬度', 'after' => 'lng'])
              ->addColumn('logo', 'string', ['limit' => 255, 'default' => '', 'comment' => '公司logo', 'after' => 'lat'])
              ->addColumn('contact', 'string', ['limit' => 255, 'default' => '', 'comment' => '联系人', 'after' => 'logo'])
              ->addColumn('phone', 'string', ['limit' => 255, 'default' => '', 'comment' => '联系电话', 'after' => 'contact'])
              ->addColumn('email', 'string', ['limit' => 255, 'default' => '', 'comment' => '邮箱', 'after' => 'phone'])
              ->addColumn('status', 'integer', ['limit' => 11, 'default' => 1, 'comment' => '状态：1启用 2禁用', 'after' => 'email'])
              ->addColumn('sort', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '排序', 'after' => 'status'])
              ->addColumn('remark','string',['limit' => 255, 'default' => '', 'comment' => '备注', 'after' => 'type'])
              ->addColumn('create_time', 'integer', ['limit' => 11, 'default' => null, 'comment' => '创建时间', 'after' => 'remark'])
              ->addColumn('update_time', 'integer', ['limit' => 11, 'default' => null, 'comment' => '更新时间', 'after' => 'create_time'])
              ->addColumn('delete_time', 'integer', ['limit' => 11, 'default' => null, 'comment' => '删除时间', 'after' => 'update_time'])
              ->addIndex(['group_id'], ['name' => 'idx_group_id'])
              ->addIndex(['name','phone'], ['unique' => true, 'name' => 'idx_name_phone'])
              ->create();

    }
}
